/* 
Scenic Graphics Library
Copyright (C) 2007 Jouni Tulkki

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USApackage scenic;
*/

#include "DynArray.h"

#define VSF_TEX0		0
#define VSF_TEX1		1
#define VSF_TEX2		2

#define VSF_TEXCOORD2	0
#define VSF_TEXCOORD3	4

namespace Scenic
{
namespace Renderer
{
struct COMMON_VERTEX
{
	float x;
	float y;
	float z;
	int diffuse;
	float tex[6];
};

struct VERTEX_INFO
{
	int index;
	float p[2];
	int diffuse;
	float tex[2][3];
};

struct Rect
{
	int left;
	int top;
	int right;
	int bottom;
};

class Context;
class Affine2;
class ClipArea;

class VertexStore
{
	Context *context;
	Affine2 *tm;
	int type;
	int numTextures;
	int numDimensions;
	int vertexSize;
	Rect clipRect;

	DynArray<char> vertices;
	DynArray<int> indices;
	int numVertices;
	float default_tu2, default_tv2;
	int offset;
	float clipOffsetX;
	float clipOffsetY;
public:
	VertexStore();
	VertexStore(int type, Context *context, Affine2 *tm, ClipArea *clip = 0);

	void setContext(Context *context);
	void setTransform(Affine2 *tm);
	void setType(int type);
	int getType() { return type; }

	int getNumVertices() { return numVertices; }
	int getNumTriangles() { return indices.size / 3; }
	bool isEmpty() { return indices.size == 0; }

	void init(int type, Context *context, Affine2 *tm, ClipArea *clip);
	int addVertex(double x, double y, int diffuse);
	int addVertex(double x, double y, int diffuse, float tu1, float tv1);
	int addVertex(double x, double y, int diffuse, float tu1, float tv1, float tu2, float tv2);
	int addVertex(VERTEX_INFO *vertex);
	void addTriangle(int a, int b, int c);
	void setDefaultTex2(float tu2, float tv2);
//	VERTEX_INFO &getVertex(int index) { return block[index]; }
	void endBlock();
	void draw();
	void empty();
};
}
}
